package app;

import common.struct.SensorInfo;
import common.struct.CtxServiceConfig;
import common.struct.SensorData;
import common.struct.State;
import common.struct.ConstantEnum.SensorMode;
import common.struct.ConstantEnum.ServiceType;

import java.util.Map;

public class zlyAppDemo extends AbstractApp{
    @Override
    public void getMsg(String sensorName, SensorData value) {
        logger.info(String.format("[%s]: getMsg(channel, msg) -> %s, %s", appName, sensorName, value));
    }

    @Override
    public void configApp() {

    }

    public static void main(String[] args) {
        zlyAppDemo demo = new zlyAppDemo();
        AppRemoteConnector connector = AppRemoteConnector.getInstance();
        connector.connectPlatform("127.0.0.1", 9090);
        connector.registerApp(demo);

        String sensorName = "YellowCar";

        Map<String, SensorInfo> supportedSensors = connector.getSupportedSensors();
        if(supportedSensors.containsKey(sensorName) &&
        supportedSensors.get(sensorName).state == State.ON){
            connector.registerSensor(sensorName, SensorMode.ACTIVE, -1);
        }

        CtxServiceConfig ctxServiceConfig = new CtxServiceConfig();
        ctxServiceConfig.setCtxResources("Resources/config/platform/ctx/zlyTest/appTwo/taxiRules.xml",
                "Resources/config/platform/ctx/zlyTest/appTwo/taxiPatterns.xml",
                "Resources/config/platform/ctx/zlyTest/appTwo/taxiBfunction.java",
                "Resources/config/platform/ctx/zlyTest/appTwo/taxiMfunction.java",
                null);
        connector.serviceStart(ServiceType.CTX, ctxServiceConfig);
        while (true);
    }
}
